// 默认的 服务  用于同一修改

let baseUrl = ''
// let COSName = ''
// let Region = ''

const checkIP = (ip) => {
  const reg = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
  if (reg.test(ip)) {
    if (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256) {
      return true
    } else {
      return false
    }
  }
}

const getApiUrl = prefix => {
  let arr = window.location.hostname
  if (checkIP(arr)) {
    arr = arr + ':8104'
  } else {
    arr = prefix + '-' + arr
  }
  const url = window.location.protocol + '//' + arr
  return url
}

if (process.env.NODE_ENV === 'production') {
  baseUrl = getApiUrl('api')
  // COSName = 'xicheng-1303913545'
  // Region = 'ap-guangzhou'
} else {
  // COSName = 'xicheng-1303913545'
  // Region = 'ap-guangzhou'
  baseUrl = getApiUrl()
  // baseUrl = 'http://192.168.1.162:8104'
}

export {
  baseUrl
}
